package com.tsingteng.cosfun.ui.message.systemnotification;

import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.tsingteng.cosfun.R;
import com.tsingteng.cosfun.base.BasePresenterFragment;
import com.tsingteng.cosfun.bean.SystemNotificationBean;
import com.tsingteng.cosfun.widget.MyRecycleView;
import com.tsingteng.cosfun.widget.TitleView;

import butterknife.BindView;

/**
 * 系统通知
 * 常胜；
 * 2018.8.11
 * */
public class SystemNotificationFragment extends BasePresenterFragment<SystemNotificationPresenter, SystemNotificationContract.INotificationView> implements SystemNotificationContract.INotificationView {
    @BindView(R.id.tv_notifi)
    TitleView tvNotifi;
    @BindView(R.id.rv_notifi_rv)
    MyRecycleView rvNotifiRv;
    private String type = "NOTICE";
    private int page = 1;

    public static SystemNotificationFragment newInstance() {
        SystemNotificationFragment fragment = new SystemNotificationFragment();
        return fragment;
    }
    @Override
    protected void initData(View rootView) {
        mPresenter.loginSystemNotification(type,page);
        tvNotifi.setTitle("系统通知");
        tvNotifi.setIvLeft(R.drawable.back_big_icon);
        tvNotifi.setOnTitleClickListener(new TitleView.OnTitleClickListener() {
            @Override
            public void onLeft() {
                getActivity().finish();
            }

            @Override
            public void onRight() {

            }

            @Override
            public void onRight2() {

            }
        });
    }

    @Override
    protected SystemNotificationPresenter createPresenter() {
        return new SystemNotificationPresenter();
    }

    @Override
    protected View initHeader() {
        return null;
    }

    @Override
    protected MyRecycleView createRecycleView() {
        return rvNotifiRv;
    }

    @Override
    protected BaseQuickAdapter createAdapter() {
        return new SystemNotificationAdapter(getActivity());
    }

    @Override
    public void onItemClick(BaseQuickAdapter adapter, View view, int position) {

    }

    @Override
    public void onLoadMoreRequested() {
        page++;
        mPresenter.loginSystemNotification(type,page);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_system_notification;
    }


    @Override
    protected void refresh() {
        page = 1;
        mAdapter.getData().clear();
        mPresenter.loginSystemNotification(type,page);
    }

    @Override
    public void showSystemNotificationData(SystemNotificationBean notificationBean) {
        if (rvNotifiRv!= null) rvNotifiRv.refreshComplete();
        if (notificationBean == null || notificationBean.getList()==null) return;
        mAdapter.addData(notificationBean.getList());
        mAdapter.notifyDataSetChanged();
        if (notificationBean.isHasNextPage()) {
            mAdapter.loadMoreComplete();
        }else {
            mAdapter.loadMoreEnd();
        }

    }
}
